// pages/yuyue-list/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userimg:"",
    pname:"",
    applytime:"",
    aId:"",
    status:"",
    appoint:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userimg = app.globalData.userInfo.Avatar
    this.setData({
      userimg: userimg
    })
    this.orderList()
  },
  //获取预约列表
  orderList:function(){
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: app.globalData.host + '/api/user/AppointList?uid=' + app.globalData.userInfo.Uid,
      success: function (res) {
        var arr = res.data.Data
        var appoint = []
        for (var i = arr.length-1; i >= 0;i--){
          var list = {}
          list.pname = arr[i].PName
          list.applytime = arr[i].ApplyTime
          list.aId = arr[i].AId
          list.status = arr[i].Status
          appoint.push(list)
        }
        that.setData({
          appoint: appoint
        })
      }
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 200)
  },
  //取消预约offOrder
  offOrder:function(e){
    var that = this;
    var aid = e.currentTarget.dataset.aid
    wx.request({
      url: app.globalData.host + '/api/user/AppointCancel?aid=' + aid,
      success: function (res) {
        wx.showToast({
          title: '取消成功',
          icon: 'success',
          duration: 2000
        })
        wx.redirectTo({
          url: "/pages/yuyue-list/index",
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})